package com.punch.order.config;

import com.punch.order.constants.PayChannelEnum;
import com.punch.order.design.OrderContextFactory;
import com.punch.order.design.PayStrategy;
import com.punch.order.design.strategy.AliPayAppStrategy;
import com.punch.order.design.strategy.WxPayAppStrategy;
import com.punch.order.design.strategy.ZeroStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.Map;

@Configuration
public class PayConfig {

    @Resource
    private AliPayAppStrategy aliPayAppStrategy;

    @Resource
    private WxPayAppStrategy wxPayAppStrategy;

    @Resource
    private ZeroStrategy zeroStrategy;

    /**
     * 支付策略工厂
     *
     * @return 策略工厂
     */
    @Bean
    public OrderContextFactory orderContextFactory() {
        OrderContextFactory orderContextFactory = new OrderContextFactory();
        Map<String, PayStrategy> strategyMap = orderContextFactory.getStrategyMap();
        strategyMap.put(PayChannelEnum.ALIPAY_APP.name(), aliPayAppStrategy);
        strategyMap.put(PayChannelEnum.WXPAY_APP.name(), wxPayAppStrategy);
        strategyMap.put(PayChannelEnum.ZERO.name(), zeroStrategy);
        return orderContextFactory;

    }

}
